class User < ActiveRecord::Base
  require 'digest'
  attr_accessible :name, :address, :birth, :email, :indentify_number, :password, :phone, :sex, :user_group, :username
  validates :username, :uniqueness => true

  has_and_belongs_to_many :roles

  def authorise(password)
    if self.hased_password == Digest::SHA2.hexdigest(password + 'segroup')
      return true
    end

    return false
  end

  def password=(password)
    @password=password
    if password.present?
      self.hased_password = Digest::SHA2.hexdigest(password + 'segroup')
    end
  end

end
